package com.epam.ws.anatomist.example.service;

import java.util.Date;
import java.util.Properties;

import junit.framework.Assert;

import com.epam.ws.anatomist.example.Operation;
import com.epam.ws.anatomist.example.RequestFactory;
import com.epam.ws.anatomist.example.bindings.Request;
import com.epam.ws.anatomist.example.bindings.Response;
import com.epam.ws.anatomist.log.Logger;

public class PaymentService extends BaseService
{

	public static final PaymentServiceMock PAYMENT_SERVICE = new PaymentServiceMock();

	public PaymentService(RequestFactory factory)
	{
		super(factory);
	}

	public PaymentService()
	{
		super();
	}

	public Response createPaymentCard(Request request)
	{
		Assert.assertNotNull(request);
		Logger.storeXmlObject(request);
		Response response = PAYMENT_SERVICE.createPaymentCard(request);
		Logger.storeXmlObject(response);
		return response;
	}

	public Operation createPaymentCard(String requestCfgName, Properties customProperties)
	{
		checkIsOnFactories();
		Operation createPaymentCardOperation = factory.createRequestHolder(requestCfgName, customProperties);
		Response response = createPaymentCard((Request) createPaymentCardOperation.getRequest());
		createPaymentCardOperation.setResponse(response);
		return createPaymentCardOperation;
	}

	public Operation createPaymentCard(Operation operation)
	{
		return operation;
	}

	public Operation validate(Operation operation)
	{
		return operation;
	}

	public static class PaymentServiceMock
	{

		public Response createPaymentCard(Request request)
		{
			Assert.assertNotNull(request);
			Response response = new Response();
			if (request.getName() == null || request.getName().isEmpty())
			{
				response.setError("Element 'Name' is empty or null");
				return response;
			}
			response.setGUID(request.getGUID());
			response.setDateCreated(new Date());
			response.setId(request.getId() * 2);
			response.setName(request.getName());
			return response;
		}

	}

}
